import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/22 22:52
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int leastBricks(List<List<Integer>> wall) {
        Map<Integer, Integer> map = new HashMap<>();
        int n = wall.size();
        int max = 0;
        for (List<Integer> w: wall) {
            int sum = 0;
            for (int i = 0; i < w.size() - 1; i++) {
                sum += w.get(i);
                // 经过最少的砖块，肯定经过最多的分界线，为前缀和，但是最后的边界不加入
                map.put(sum, map.getOrDefault(sum, 0) + 1);
                max = Math.max(max, map.get(sum));
            }
        }
        return n - max;
    }
}
